﻿#region 命名空间

using System;
using WinnerCMS.BLL;
using WinnerCMS.Common;
using WinnerCMS.Model;

#endregion

namespace WinnerCMS.WebUI.Templates.WinnerCMS6.Member
{
    public partial class Exchange : WebFactory.ClientPublicPage
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            Page.Title = WebConfig.SiteName + "→ 会员中心 → 点数转换";
            if (RightsCheck.IsLogined == false)
            {
                MsgBox.Message("登录超时，请重新登录。", "Login.aspx", this);
            }
            if (Request["Action"] == "ZhuanHuan")
            {
                var config = CMSConfig.Instance();

                this.Panel1.Visible = true;
                this.Panel2.Visible = false;
                this.Label1.Text = config.Member.JingBiHuiLv.ToString();
                this.Label2.Text = Math.Round(1/config.Member.JingBiHuiLv, 10).ToString();
                this.Label3.Text = config.Member.JianYanHuiLv.ToString();
                this.lblPath.Text = "点数转换";
                //btnOK1.Attributes.Add("onclick", "return Check('A')");
            }
            else if (Request["Action"] == "ZhengYu")
            {
                this.Panel1.Visible = false;
                this.Panel2.Visible = true;
                this.lblPath.Text = "金币转赠";
            }
            else
            {
                MsgBox.Message("参数错误。", "Default.aspx", this);
            }
        }

        protected void btnOK1_Click(object sender, EventArgs e)
        {
            if (this.NumericTextBox1.Text.Length > 0)
            {
                var res = new ExchangeManage().Coin2Point(int.Parse(this.NumericTextBox1.Text));
                if (res.Errors.Length > 0)
                {
                    MsgBox.Message(res.Errors, this);
                }
                else
                {
                    MsgBox.Message("更新成功！", "Exchange.aspx?Action=ZhuanHuan", this);
                }
            }
            else
            {
                MsgBox.Message("请输入数字。", this);
            }
        }

        protected void btnOK2_Click(object sender, EventArgs e)
        {
            if (this.NumericTextBox2.Text.Length > 0)
            {
                var res = new ExchangeManage().Point2Coin(int.Parse(this.NumericTextBox2.Text));
                if (res.Errors.Length > 0)
                {
                    MsgBox.Message(res.Errors, this);
                }
                else
                {
                    MsgBox.Message("更新成功！", "Exchange.aspx?Action=ZhuanHuan", this);
                }
            }
            else
            {
                MsgBox.Message("请输入数字。", this);
            }
        }

        protected void btnOK3_Click(object sender, EventArgs e)
        {
            if (this.NumericTextBox3.Text.Length > 0)
            {
                var res = new ExchangeManage().Experience2Point(int.Parse(this.NumericTextBox3.Text));
                if (res.Errors.Length > 0)
                {
                    MsgBox.Message(res.Errors, this);
                }
                else
                {
                    MsgBox.Message("更新成功！", "Exchange.aspx?Action=ZhuanHuan", this);
                }
            }
            else
            {
                MsgBox.Message("请输入数字。", this);
            }
        }

        protected void btnOK4_Click(object sender, EventArgs e)
        {
            var strUserName = this.txtMemberName.Text.Trim();
            var Number = int.Parse(this.NtxtCoin.Text);
            var res = new ExchangeManage().CoinGive(strUserName, Number);
            if (res.Errors.Length > 0)
            {
                MsgBox.Message(res.Errors, this);
            }
            else
            {
                MsgBox.Message("操作成功！", "/Exchange.aspx?Action=ZhengYu", this);
            }
        }
    }
}